/*
* Copyright (C) 2010, Jared Jennings <jaredljennings@gmail.com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

using System;
using NUnit.Framework;
using org.jaredjennings.mysshmenu;

namespace org.jaredjennings.mysshmenu.tests
{
	[TestFixture()]
	public class StoreBackendTests
	{
		StoreBackend sb;
		[SetUp]
		public void Init()
		{
			sb = StoreBackend.GetInstance();
			
		}
		[Test()]
		public void getHost_Success ()
		{
			HostObj host1 = new HostObj();
			host1.NAME = "edirlx";
			HostObj host2 = StoreBackend.GetInstance().getHost(host1);
			Assert.IsTrue(host2.NAME.Equals("edirlx"));
		}
		
		[Test()]
		[ExpectedException("System.ArgumentOutOfRangeException")]
		public void deleteFromList_Success()
		{
			HostObj host1 = new HostObj();
			host1.NAME = "edirlx";			
			host1.ADDRESS = "172.16.1.101";
			host1.PORT = "22";
			host1.CONNTYPE = ConnectionType.SSH;
			sb.addTo(host1);
			sb.delete(host1);
			StoreBackend.GetInstance().getHost(host1);
		}

		[Test()]
		public void getHostIndex_NotFound()
		{
			HostObj host1 = new HostObj();
			host1.NAME = "edirlx2";			
			int index = sb.getHostLocInList(host1);
			Assert.IsTrue(index == -1, "Host should not have been found, but was. " +
				"Or we got back a different value than expected");
		}
		
		[Test()]
		public void UpdateList_Success()
		{
			sb = StoreBackend.GetInstance();
			HostObj hostRtrv = new HostObj();
			hostRtrv.NAME = "edirlx";
			HostObj host = sb.getHost(hostRtrv);
			//Console.WriteLine ("Current Address " + host.ADDRESS);
			host.ADDRESS = "term1.jaredjennings.org";
			sb.update(host);
			host = sb.getHost(hostRtrv);
			Assert.IsTrue("term1.jaredjennings.org".Equals(host.ADDRESS));
			
		}
		[Test()]
		public void InstanceSame_Object_Succeed()
		{
			Object obj1 = StoreBackend.GetInstance();
			Object obj2 = StoreBackend.GetInstance();
			Assert.AreSame(obj1, obj2, "Objects should be same since the class is a singleton");
		}
	}
}

